import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:oktoast/oktoast.dart';

import '../../../../widget/image_asset_widget.dart';


enum ImageWidgetType { asset, network }

class TitleTopWidget2 extends StatelessWidget {
  final String backUrl;
  final String title;
  final Color? titleColor;
  final double? titleSize;
  final String rightImage;
  final String rightText;
  final double? rightTextSize;
  final Color? rightTextColor;
  final Color? rightBgColor;
  final double? rightWidth;
  final double? rightHeight;
  final VoidCallback? onRightPressed;
  final VoidCallback? onLeftPressed;
  const TitleTopWidget2({
    super.key,
    this.backUrl = "",
    this.title = "",
    this.titleColor = Colors.white,
    this.titleSize = 18,
    this.rightImage = "",
    this.rightText = "",
    this.rightTextSize = 12,
    this.rightTextColor = Colors.white,
    this.rightBgColor = Colors.transparent,
    this.rightWidth = 65,
    this.rightHeight = 21,
    this.onRightPressed,
    this.onLeftPressed,
  });

  @override
  Widget build(BuildContext context) {
     double top = MediaQuery.of(context).padding.top;
    return Container(
      decoration: BoxDecoration(
        color: AppColors.backgroundColor
      ),
      width: context.width,
      child: Padding(padding: EdgeInsets.only(top: top),
        child: Stack(
          alignment: AlignmentDirectional.centerStart,
          children: [
              Container(
          decoration: BoxDecoration(),
          child:     Padding(padding: EdgeInsets.only(left: 25.px,right: 25.px),
              child: GestureDetector(
                child: ImageAssetWidget(
                  imageUrl: backUrl.isEmpty ? "static/images/home_shop_all_left_back_icon.png" : backUrl,
                  width: 18.px,
                  height: 18.px,
                ),
                onTap: () {
                  onLeftPressed?.call();
                  Navigator.of(context).pop();
                },
              ),),
        ),
            Positioned(
                left: 0,
                right: 0,
                child: Center(
                  child: Text(
                    "${title}",
                    style: TextStyle(
                      color: titleColor,
                      fontSize: titleSize,
                    ),
                  ),
                )
            ),
            Positioned(
              right: 0,
              child: Container(
                  width: rightWidth,
                  height: rightHeight,
                  decoration: rightImage.isEmpty?BoxDecoration(
                    color: rightBgColor,
                    borderRadius: BorderRadius.circular(15.px,), // 设置圆角
                  ):BoxDecoration(),
                  child: GestureDetector(
                    child: Center(
                        child: rightImage.isEmpty?Text(
                          "${rightText}",
                          style: TextStyle(
                            color: rightTextColor,
                            fontSize: rightTextSize,
                          ),
                        ):ImageAssetWidget(
                          imageUrl: rightImage,
                          width: rightWidth,
                          height: rightHeight,
                        )
                    ),
                    onTap: (){
                      onRightPressed?.call();
                    },
                  )
              ),
            ),
          ],
        ),
      ),
    );
  }
}
